<?php
/**
 * Description of loadProperties
 *
 * @author rocco
 */

class WebApplicationInit
{
    private $host;
    private $user;
    private $database;
    private $password;
    private $internalPath;
    private $serverFTP;
    private $usernameFTP;
    private $passwordFTP;
    private $commercialEmail;
    private $commercialName;
    private $smsUserId;
    private $smsPassword;
    private $context;
    private static $instance;
//    private $numConnection;

    public function  __destruct()
    {
    }
    
    public function initDB()
    {
        $fileDBProperties=fopen("../classes/conf/db.properties","r");
//lettura host
        $buffer = fgets($fileDBProperties);
        $tmp1 = explode("=", $buffer);
        $this->host = trim($tmp1[1]);
       
//lettura user
        $buffer = fgets($fileDBProperties);
        $tmp2 = explode("=", $buffer);
        $this->user =trim($tmp2[1]);

        //lettura db
        $buffer = fgets($fileDBProperties);
        $tmp3 = explode("=", $buffer);
        $this->database =trim($tmp3[1]);

        //lettura password
        $buffer = fgets($fileDBProperties);
        $tmp4 = explode("=", $buffer);
        $this->password =trim($tmp4[1]);
        
//        printf(" host %s\n", $this->host);
//        printf(" user %s\n", $this->user);
//        printf(" database %s\n", $this->database);
//        printf(" password %s\n", $this->password);

        fclose ($fileDBProperties); 
    }
    
    public function initContext()
    {
       $fileInitProperties=fopen("../classes/conf/init.properties","r");
       $buffer = fgets($fileInitProperties);
       $tmp1 = explode("=", $buffer);
       $this->internalPath = trim($tmp1[1]);      
       $buffer = fgets($fileInitProperties);
       $tmp2 = explode("=", $buffer);
       $this->context = trim($tmp2[1]);
       //printf(" internal path %s\n", $this->internalPath);
       fclose ($fileInitProperties); 
    }
    
    public function initMailServices()
    {      
      $fileEmailProperties=fopen("../classes/conf/emailServices.properties","r");
      $buffer = fgets($fileEmailProperties);
      $tmp = explode("=", $buffer);
      $this->commercialEmail = trim($tmp[1]);
      $buffer1 = fgets($fileEmailProperties);
      $tmp1 = explode("=", $buffer1);
      $this->commercialName = trim($tmp1[1]);
      $buffer2 = fgets($fileEmailProperties);
      $tmp2 = explode("=", $buffer2);
      $this->smsUserId = trim($tmp2[1]);
      $buffer3 = fgets($fileEmailProperties);
      $tmp3 = explode("=", $buffer3);
      $this->smsPassword = trim($tmp3[1]);
    }
    
    public static function getInstance()
    {
        if(self::$instance == null)
        {
            $c = __CLASS__;
            self::$instance = new $c;
            self::$instance->initDB();
            self::$instance->initContext();
            self::$instance->initMailServices();
        }
        return self::$instance;
    }

    

    public function getHost()
    {
        return $this->host;
    }

    public function getUser()
    {
        return $this->user;
    }

    public function getDatabase()
    {
        return $this->database;
    }

    public function getPassword()
    {
        return $this->password;
    }

    public function getInternalPath()
    {
        return $this->internalPath;
    }

     public function getServerFTP()
    {
        return $this->serverFTP;
    }

     public function getUsernameFTP()
    {
        return $this->usernameFTP;
    }

     public function getPasswordFTP()
    {
        return $this->passwordFTP;
    }
     public function getCommercialMail()
    {
        return $this->commercialEmail;
    }

     public function getCommercialName()
    {
        return $this->commercialName;
    }
     public function getSmsUserId()
    {
        return $this->smsUserId;
    }

     public function getSmsPassword()
    {
        return $this->smsPassword;
    }
     public function getContext()
    {
        return $this->context;
    }
}
?>
